/**
 * 
 */
package com.pdt.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.pdt.service.RobotServiceDAO;
import com.pdt.util.ResponseUtil;

/**
 * @author 作者：Zhangyangyang
 * @version 创建时间：2017年6月16日 下午1:34:05 类说明
 */
@Controller
public class RobotController {
	
	@Autowired
	private RobotServiceDAO robotServiceDAO;
	
	//用户登录
	@RequestMapping(value = "/pdt/login", method = RequestMethod.POST)
	@ResponseBody
	public void login(@RequestBody JSONObject data, HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		ResponseUtil.write(response, robotServiceDAO.login(data));
	}
	//几个不同机器人扫码的界面
	@RequestMapping(value = "/pdt/inSnowHouse")
	public String inSnowHouse(){
		return "inSnowHouse";
	}
	@RequestMapping(value = "/pdt/inMealsHouse")
	public String inMealsHouse(){
		return "inMealsHouse";
	}
	@RequestMapping(value = "/pdt/inWelHouse")
	public String inWelHouse(){
		return "inSnowHouse";
	}
	@RequestMapping(value = "/pdt/addClients")
	public String addClients(){
		return "addClients";
	}
	@RequestMapping(value = "/pdt/outHouse")
	public String outHouse(){
		return "outHouse";
	}
	// 机器人入库
	@RequestMapping(value = "/pdt/toHouse", method = RequestMethod.POST,consumes = "application/json")
	@ResponseBody
	public void  inHouse(@RequestBody JSONObject data, HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		ResponseUtil.write(response,robotServiceDAO.inHouse(data));
		
	}
	
	//机器人出库
	@RequestMapping(value = "/pdt/outHouse", method = RequestMethod.POST)
	@ResponseBody
	public void outHouse(@RequestBody JSONObject data, HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		ResponseUtil.write(response, robotServiceDAO.outHouse(data));
	}
	
	//查询sn
	@RequestMapping(value = "/pdt/searchSN", method = RequestMethod.POST)
	@ResponseBody
	public void searchSN(@RequestBody JSONObject data, HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		ResponseUtil.write(response, robotServiceDAO.searchSN(data));
	}
	
	//添加商户
	@RequestMapping(value = "/pdt/addMerchants", method = RequestMethod.POST)
	@ResponseBody
	public void addMerchants(@RequestBody JSONObject data, HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		ResponseUtil.write(response, robotServiceDAO.addMerchants(data));
	}
	
	//异步根据sn查询其他信息
	@RequestMapping(value = "/pdt/showSnInfo", method = RequestMethod.POST)
	@ResponseBody
	public void showSnInfo(@RequestBody JSONObject data, HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		ResponseUtil.write(response, robotServiceDAO.getRobotBySn(data));
	}
	
	
}
